package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAddressMapper;
import com.qf.pojo.DtsAddress;
import com.qf.service.DtsAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project E-commercebackGroundManagementSystem
 * @date 2022/9/22 15:09
 */
@Service
public class DtsAddressServiceImpl implements DtsAddressService {
    @Autowired
    private DtsAddressMapper dtsAddressMapper;
    @Override
    public Page<DtsAddress> selectPage(String name, Integer userId, Integer page, Integer limit, String sort, String order) {
        Page<DtsAddress> dtsAddressPage = new Page<>(page, limit);
        QueryWrapper<DtsAddress> dtsAddressQueryWrapper = new QueryWrapper<>();
        dtsAddressQueryWrapper.orderBy(!StringUtils.isEmpty(sort),"asc".equalsIgnoreCase(order),sort).like(!StringUtils.isEmpty(name),"name",name).eq(userId!=null,"user_id",userId).eq("deleted",false);


        return dtsAddressMapper.selectPage(dtsAddressPage,dtsAddressQueryWrapper);
    }
}
